package loader

import (
	"game/game-design/loader/consttype"
	"strconv"
	"strings"
)

type DesignDefine struct {
	//列名相对表头定义的偏移行数
	NameOffset int
	//列类型相对表头定义的偏移行数
	TypeOffset int
	//列标签相对表头定义的偏移行数
	TagOffset int
	//列备注相对表头定义的偏移行数
	CommentOffset int
	//双方都导出的标签名
	BothTag string
	//服务器导出的标签名
	ServerTag string
	//客户端导出的标签名
	ClientTag string
	//双方都不导出的标签名
	NoneTag string
	//填写模式
	Mode string
}

// func DefaultDesignDefine() *DesignDefine {
// 	var designDefine DesignDefine
// 	designDefine.NameOffset = 1
// 	designDefine.TypeOffset = 2
// 	designDefine.TagOffset = 3
// 	designDefine.CommentOffset = 4
// 	designDefine.BothTag = "all"
// 	designDefine.ServerTag = "server"
// 	designDefine.ClientTag = "client"
// 	designDefine.NoneTag = "no"
// 	return &designDefine
// }

func (d *DesignDefine) ExportType(exportSymbol string) consttype.ExportType {
	if d.BothTag == exportSymbol {
		return consttype.BOTH
	} else if d.ServerTag == exportSymbol {
		return consttype.SERVER
	} else if d.ClientTag == exportSymbol {
		return consttype.CLIENT
	} else {
		return consttype.NONE
	}
}

func (d *DesignDefine) Form(values []string) {
	// name:1 type:2 tag:4 comment:3 bothTag:all serverTag:server clientTag:client ignoreTag:-
	for _, v := range values {
		parts := strings.Split(v, ":")
		if parts[0] == "name" {
			d.NameOffset, _ = strconv.Atoi(parts[1])

		} else if parts[0] == "type" {
			d.TypeOffset, _ = strconv.Atoi(parts[1])

		} else if parts[0] == "tag" {
			d.TagOffset, _ = strconv.Atoi(parts[1])

		} else if parts[0] == "comment" {
			d.CommentOffset, _ = strconv.Atoi(parts[1])

		} else if parts[0] == "bothTag" {
			d.BothTag = parts[1]

		} else if parts[0] == "serverTag" {
			d.ServerTag = parts[1]

		} else if parts[0] == "clientTag" {
			d.ClientTag = parts[1]

		} else if parts[0] == "ignoreTag" {
			d.NoneTag = parts[1]
		}
	}
}
